﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule.CallRoute;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.Persistent;
using Jumpton.SFA.Entity;

public partial class VisitBasicInfo : System.Web.UI.Page
{
    private decimal visitId;
    // private int type;
    private RouteManager manager = new RouteManager();
    protected String photoInfo = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            visitId = decimal.Parse(Request.QueryString["visitid"]);
        }
        catch (Exception)
        {
            return;
        }
        //try
        //{
        //    type = int.Parse(Request.QueryString["type"]);
        //}
        //catch (Exception)
        //{
        //    return;
        //}
        InitPage();

        ////控制展示页面
        //if (1 == type)
        //{

        //}
        //else if (4 == type)
        //{
        //}
    }

    private void InitPage()
    {
        VISITS visit = manager.LoadVisits(visitId);
        Person person = new PersonManager().Load(int.Parse(visit.personid.ToString()));
        CUSTOMERS customer = new CustomerManager().Load(visit.CUSTOMERID);
        lblCustomer.Text = customer.NAME;
        try
        {
            DictionaryItems di = new DictionaryItemsManager().Load(decimal.Parse(customer.CUSTCLASSCODE));


            lblChannel.Text = di.Name;
        }
        catch { }
        lblUser.Text = person.Name;

        string starttime = BusinessLogic.GetDateTime(visit.STARTTIME.ToString());
        string endtime = BusinessLogic.GetDateTime(visit.STOPTIME.ToString());
        lblStart.Text = starttime;
        lblStop.Text = endtime;
        lblTimeSpan.Text = DateDiff(DateTime.Parse(endtime),DateTime.Parse(starttime));
        lblRemark.Text = visit.Note;
        lbl_latitude.Text = visit.LATITUDE.ToString();
        lbl_longitude.Text = visit.LONGITUDE.ToString();

    }

    //计算两个日期日期的时间差
    private string DateDiff(DateTime DateTime1, DateTime DateTime2)
    {
        string dateDiff = "";
        try
        {
            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();


            if (ts.Days != 0) dateDiff += ts.Days.ToString() + "天";
            if (ts.Hours != 0) dateDiff += ts.Hours.ToString() + "小时";
            if (ts.Minutes != 0) dateDiff += ts.Minutes.ToString() + "分钟";
            dateDiff += ts.Seconds.ToString() + "秒";

        }
        catch
        {

        }
        return dateDiff;
    }

}